package com.hooper.hosp.controller;

import com.hooper.cmn.client.DictClient;
import com.hooper.hosp.model.hosp.Hospital;
import com.hooper.hosp.model.hosp.Schedule;
import com.hooper.hosp.service.HospService;
import com.hooper.hosp.service.ScheduleService;
import com.hooper.hosp.vo.hosp.HospitalQueryVo;
import com.hooper.hospital.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2022/09/28/21:01
 */
@Api("hosp controller")
@RestController
@Slf4j
@RequestMapping("/admin/hosp/hospital")
public class HospController {

    @Resource
    private DictClient dictClient;
    @Resource
    private HospService hospService;
    @Resource
    private ScheduleService scheduleService;

    @ApiOperation("")
    @PostMapping("list/{currentPage}/{pageSize}")
    public Result<Page<Hospital>> pageByConditions(@PathVariable Integer currentPage,
                                                   @PathVariable Integer pageSize,
                                                   @RequestBody(required = false) HospitalQueryVo hospQueryVo) {
        Page<Hospital> pageList = hospService.pageByConditions(currentPage, pageSize, hospQueryVo);
        log.info("dict-client====>{}", dictClient);
        pageList.getContent().forEach(item -> {
            hospService.completeHosp(item);
        });
        return Result.ok(pageList);
    }

    @PostMapping("changeStatus/{id}/{status}")
    public Result<String> changeStatus(@PathVariable String id, @PathVariable String status) {
        hospService.changeStatus(id, status);
        log.info("{}===>{}", id, status);
        return Result.ok();
    }

    @GetMapping("/detail/{id}")
    public Result<Hospital> getHospDetail(@PathVariable String id) {
        return Result.ok(hospService.getHospDetailById(id));
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetail(hoscode, depcode, workDate));
    }


    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/getSchedule/{scheduleId}")
    public Result<Schedule> getSchedule(@PathVariable String scheduleId) {
        return Result.ok(scheduleService.getScheduleById(scheduleId));
    }
}
